#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Models/Marketmodels/CurveState.h>
#pragma unmanaged 
#include <ql\models\marketmodels\curvestates\cmswapcurvestate.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Models { namespace Marketmodels { namespace Curvestates {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ICMSwapCurveState
	public ref class CCMSwapCurveState  : 
            public CCurveState,
            public Cephei::QL::Models::Marketmodels::Curvestates::ICMSwapCurveState
	{
	protected: 
		boost::shared_ptr<QuantLib::CMSwapCurveState>* _ppCMSwapCurveState;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CMSwapCurveState>* _phCMSwapCurveState;
#endif
		Object^ _CMSwapCurveStateOwner;     // reference to object that manages the storage for this object
	internal:
		CCMSwapCurveState (Cephei::Core::IVector<Double>^ rateTimes, UInt64 spanningForwards);
        CCMSwapCurveState (boost::shared_ptr<QuantLib::CMSwapCurveState>& childNative, Object^ owner);
        CCMSwapCurveState (QuantLib::CMSwapCurveState& childNative, Object^ owner);
        CCMSwapCurveState (CCMSwapCurveState^ copy);
        CCMSwapCurveState (PLATFORM::Type^ t);
#ifdef STRUCT
        CCMSwapCurveState (QuantLib::CMSwapCurveState childNative);
#endif       
#ifdef HANDLE
		CCMSwapCurveState (QuantLib::Handle<QuantLib::CMSwapCurveState>& childNative, Object^ owner);
		CCMSwapCurveState (QuantLib::Handle<QuantLib::CMSwapCurveState> childNative);
#endif
		virtual ~CCMSwapCurveState ();
		!CCMSwapCurveState ();

	internal:
		QuantLib::CMSwapCurveState& GetReference ();
		boost::shared_ptr<QuantLib::CMSwapCurveState>& GetShared ();
		QuantLib::CMSwapCurveState* GetPointer ();
        void SetCMSwapCurveState (boost::shared_ptr<QuantLib::CMSwapCurveState> native)
        {
            if (_ppCMSwapCurveState != NULL)
                delete _ppCMSwapCurveState;
            _ppCMSwapCurveState = new boost::shared_ptr<QuantLib::CMSwapCurveState> (native);
            SetCurveState (boost::dynamic_pointer_cast<QuantLib::CurveState> (*_ppCMSwapCurveState));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CMSwapCurveState>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
		virtual Double CmSwapAnnuity (UInt64 numeraire, UInt64 i, UInt64 spanningForwards) ;
		virtual Double CmSwapRate (UInt64 i, UInt64 spanningForwards) ;
		virtual Cephei::Core::IVector<Double>^ CmSwapRates (UInt64 spanningForwards) ;
		virtual Double CoterminalSwapAnnuity (UInt64 numeraire, UInt64 i) ;
		virtual Double CoterminalSwapRate (UInt64 i) ;
        property Cephei::Core::IVector<Double>^ CoterminalSwapRates 
        {
		    virtual Cephei::Core::IVector<Double>^ get () ;
        }
		virtual Double DiscountRatio (UInt64 i, UInt64 j) ;
		virtual Double ForwardRate (UInt64 i) ;
        property Cephei::Core::IVector<Double>^ ForwardRates 
        {
		    virtual Cephei::Core::IVector<Double>^ get () ;
        }
		virtual Cephei::QL::Models::Marketmodels::Curvestates::ICMSwapCurveState^ SetOnCMSwapRates (Cephei::Core::IVector<Double>^ cmSwapRates, Microsoft::FSharp::Core::FSharpOption<UInt64>^ firstValidIndex) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Models::Marketmodels::Curvestates::ICMSwapCurveState^>::typeid)]
	[FactoryFor(Cephei::QL::Models::Marketmodels::Curvestates::ICMSwapCurveState::typeid)]
	[FactoryFor(Cephei::QL::Models::Marketmodels::Curvestates::ICMSwapCurveState_Factory::typeid)]
	public ref class CCMSwapCurveState_Factory sealed : public ICMSwapCurveState_Factory
	{
	public:
        virtual ICMSwapCurveState^ Create (Cephei::Core::IVector<Double>^ rateTimes, UInt64 spanningForwards);
    };
   
/*Cephei*/ } /*QL*/ } /*Models*/ } /*Marketmodels*/ } /*Curvestates */}
